package bdd.sql.server.bean;

//import java.util.Date;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Bean Video.
 * @author Guillaume Pocas & Jean-Fraçois Augé
 */
@Entity
@Table(name = "kraken_video")
public class Video {

	@Id
	@GeneratedValue
	@Column(name = "video_id")
	private int video_id;
	
	@Column(name = "video_name", unique = true, nullable = false, updatable = false)
	private String video_name;
	
	@Column(name = "video_path", nullable = false, updatable = true)
	private String video_path;
	
	@ManyToOne
    @JoinColumn(name = "id_camera")
	private Camera camera;
	
	@ManyToOne
    @JoinColumn(name = "id_storage")
	private ServerStorage storage;
	
	@Column(name = "video_year", nullable = false)
	private String video_year;
	
	@Column(name = "video_month", nullable = false)
	private String video_month;
	
	@Column(name = "video_day", nullable = false)
	private String video_day;
	
	@Column(name = "video_timeBegin", nullable = false)
	private String video_timeBegin;
	
	@Column(name = "video_duration", nullable = false)
	private String video_duration;
	
	@Column(name = "weight", nullable = true, updatable = true)
	private long video_weight;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "video", orphanRemoval = true, cascade = CascadeType.ALL)
	private Set<Keystore> keystore;
	
	/**
	 * Constructeur vide.
	 */
	public Video() {}
	
	/**
	 * Créer une nouvelle Video.
	 * @param name
	 * @param videoPath
	 * @param cam
	 * @param stor
	 * @param year
	 * @param month
	 * @param day
	 * @param timeBegin
	 * @param timeEnd
	 */
	public Video(String name, String videoPath, Camera cam, ServerStorage stor, String year, String month, String day, String timeBegin, String duration) {
		this.video_name = name;
		this.video_path = videoPath;
		this.camera = cam;
		this.storage = stor;
		this.video_year = year;
		this.video_month = month;
		this.video_day = day;
		this.video_timeBegin = timeBegin;
		this.video_duration = duration;
		this.keystore = new HashSet<Keystore>();
	}
	
	/**
	 * Créer une nouvelle Video.
	 * @param name
	 * @param videoPath
	 * @param cam
	 * @param stor
	 * @param year
	 * @param month
	 * @param day
	 * @param timeBegin
	 * @param timeEnd
	 * @param weight
	 */
	public Video(String name, String videoPath, Camera cam, ServerStorage stor, String year, String month, String day, String timeBegin, String duration, long weight) {
		this.video_name = name;
		this.video_path = videoPath;
		this.camera = cam;
		this.storage = stor;
		this.video_year = year;
		this.video_month = month;
		this.video_day = day;
		this.video_timeBegin = timeBegin;
		this.video_duration = duration;
		this.video_weight = weight;
		this.keystore = new HashSet<Keystore>();
	}
	
	/**
	 * Créer une nouvelle Video.
	 * @param name
	 * @param videoPath
	 * @param cam
	 * @param stor
	 * @param year
	 * @param month
	 * @param day
	 * @param timeBegin
	 * @param timeEnd
	 * @param weight
	 * @param keystore
	 */
	public Video(String name, String videoPath, Camera cam, ServerStorage stor, String year, String month, String day, String timeBegin, String duration, long weight, Keystore keystore) {
		this.video_name = name;
		this.video_path = videoPath;
		this.camera = cam;
		this.storage = stor;
		this.video_year = year;
		this.video_month = month;
		this.video_day = day;
		this.video_timeBegin = timeBegin;
		this.video_duration = duration;
		this.video_weight = weight;
		this.keystore = new HashSet<Keystore>();
		this.keystore.add(keystore);
	}

	public int getVideo_id() { return video_id;	}
	public void setVideo_id(int video_id) { this.video_id = video_id;	}

	public String getVideo_name() { return video_name;	}
	public void setVideo_name(String video_name) { this.video_name = video_name;	}

	public String getVideo_path() {	return video_path;	}
	public void setVideo_path(String video_path) {	this.video_path = video_path;	}
	
	public Camera getCamera() { return camera;	}
	public void setCamera(Camera camera) { this.camera = camera;	}
	
	public ServerStorage getStorage() { return storage;	}
	public void setStorage(ServerStorage servStorage) { this.storage = servStorage;	}

	public String getVideo_year() {	return video_year;	}
	public void setVideo_year(String video_year) {	this.video_year = video_year;	}

	public String getVideo_month() {	return video_month;	}
	public void setVideo_month(String video_month) {	this.video_month = video_month;	}

	public String getVideo_day() {	return video_day;	}
	public void setVideo_day(String video_day) {	this.video_day = video_day;	}

	public String getVideo_timeBegin() { return video_timeBegin;	}
	public void setVideo_timeBegin(String video_timeBegin) { this.video_timeBegin = video_timeBegin;	}

	public String getVideo_duration() { return video_duration;	}
	public void setVideo_duration(String video_duration) { this.video_duration = video_duration;	}

	public long getVideo_weight() { return video_weight;	}
	public void setVideo_weight(long video_weight) { this.video_weight = video_weight;	}

	public Set<Keystore> getKeystore() {	return keystore;	}
	public void setKeystore(Set<Keystore> keystore) {	this.keystore = keystore;	}
	public void addKeystore(Keystore keystore){	this.keystore.add(keystore);	}
	public void delKeystore(Keystore keystore){	this.keystore.remove(keystore);	}

	@Override
	public String toString() { return String.valueOf(this.getVideo_id()); }

}
